<@pp.dropOutputFile/>
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign package = doc.groupid?replace(".", "/")> 
<#assign package = package + "/" + doc.artifactid?replace(".", "/")>
<#assign package = package + "/" + table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name="/main/" + package + "/service/" + fileName + "ServiceImpl.java"/>
package ${package?replace("/", ".")}.service;

import java.util.LinkedList;
import java.util.List;
import java.util.Arrays;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xust.common.Result;
import org.xust.common.pagination.domain.Page;
import ${package?replace("/", ".")}.dao.${table.name?cap_first}Dao;
import ${package?replace("/", ".")}.domain.${fileName};

/**
 * Class ${fileName}ServiceImpl
 * ${fileName}Service interface implementation.
 * @author ${doc.author}
 * @version ${doc.version}, ${doc.date}
 */
@Service("${table.name?uncap_first}Service")
public class ${fileName}ServiceImpl implements ${fileName}Service{
	private final static Log logger = LogFactory.getLog(${table.name?cap_first}ServiceImpl.class);
	
	@Autowired
	private ${table.name?cap_first}DaoImpl ${table.name?uncap_first}Dao;
	public void set${table.name?cap_first}Dao(${table.name?cap_first}Dao ${table.name?uncap_first}Dao) {
		this.${table.name?uncap_first}Dao = ${table.name?uncap_first}Dao;
	}

	///////////////////////////////////////////////////////////////////
		
	@Override
	public List<${table.name?cap_first}> findAll() {
		List<${table.name?cap_first}> result = new LinkedList<${table.name?cap_first}>();
		try{
			result = ${table.name?uncap_first}Dao.findAll();
		}catch(Exception e){
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public Result<Integer> insert(${table.name?cap_first} newValue) {
		Result<Integer> result = new Result<Integer>(-1);
		try{
			result.setValue(${table.name?uncap_first}Dao.insert(newValue));
		}catch(Exception e){
			result.setMessage(e.getLocalizedMessage());
			result.setDetail(e.getMessage());
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public Result<Integer> deleteById(int id) {
		Result<Integer> result = new Result<Integer>(-1);
		try{
			result.setValue(${table.name?uncap_first}Dao.deleteById(id));
		}catch(Exception e){
			result.setMessage(e.getLocalizedMessage());
			result.setDetail(e.getMessage());
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public ${table.name?cap_first} findById(int id) {
		${table.name?cap_first} result = null;
		try{
			result = ${table.name?uncap_first}Dao.findById(id);
		}catch(Exception e){
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public Result<Integer> update(${table.name?cap_first} newValue) {
		Result<Integer> result = new Result<Integer>(-1);
		try{
			result.setValue(${table.name?uncap_first}Dao.update(newValue));
		}catch(Exception e){
			result.setMessage(e.getLocalizedMessage());
			result.setDetail(e.getMessage());
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public Result<Integer> size() {
		Result<Integer> result = new Result<Integer>(-1);
		try{
			result.setValue(${table.name?uncap_first}Dao.size());
		}catch(Exception e){
			result.setMessage(e.getLocalizedMessage());
			result.setDetail(e.getMessage());
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public Result<Integer> deleteAll() {
		Result<Integer> result = new Result<Integer>(-1);
		try{
			result.setValue(${table.name?uncap_first}Dao.deleteAll());
		}catch(Exception e){
			result.setMessage(e.getLocalizedMessage());
			result.setDetail(e.getMessage());
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public List<${table.name?cap_first}> findPage(Page page) {
		return ${table.name?uncap_first}Dao.findPage(page.getShowCount() * (page.getCurrentPage() - 1), page.getShowCount());
	}

	@Override
	public Result<Integer> deleteItems(Integer[] items) {
		
		Result<Integer> result = new Result<Integer>(-1);
		try{
			result.setValue(${table.name?uncap_first}Dao.deleteItems(items));
		}catch(Exception e){
			result.setMessage(e.getLocalizedMessage());
			result.setDetail(e.getMessage());
			logger.error(e.getMessage());
		}
		return result;
	}

}
</#list>